package com.amorcloud.pig.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amorcloud.pig.R;
import com.amorcloud.pig.bean.CheckBean;
import com.amorcloud.pig.bean.PigInfoBean;

import java.util.List;

/**
 * 数据上传，盘点数据展示
 */
public class UploadCheckDataAdapter extends BaseAdapter {

    List<CheckBean> list;
    Context mContext;
    LayoutInflater inflater;

    public UploadCheckDataAdapter(Context context, List<CheckBean> beans) {
        list = beans;
        mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            convertView = inflater.inflate(R.layout.item_upload_data, null);
            viewHolder = new ViewHolder();
            viewHolder.data1 = convertView.findViewById(R.id.tv_upload_data_1);
            viewHolder.data2 = convertView.findViewById(R.id.tv_upload_data_2);
            viewHolder.data3 = convertView.findViewById(R.id.tv_upload_data_3);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.data1.setText(list.get(position).getOddNumber());
        viewHolder.data2.setText(list.get(position).getDateTime());
        if(TextUtils.isEmpty(list.get(position).getUpLoadSuccess())) {
            viewHolder.data3.setText("");
        } else {
            //viewHolder.data3.setText(list.get(position).getIsUpload().equals("0") ? "上传失败" : "上传成功");
            if(list.get(position).getUpLoadSuccess().equals("0")) {
                viewHolder.data3.setText("上传失败");
                viewHolder.data1.setTextColor(Color.RED);
                viewHolder.data2.setTextColor(Color.RED);
                viewHolder.data3.setTextColor(Color.RED);
            } else {
                viewHolder.data3.setText("上传成功");
                viewHolder.data3.setTextColor(Color.GREEN);
            }
        }
        return convertView;
    }

    private class ViewHolder{
        TextView data1, data2, data3;
    }

    public void setData(List<CheckBean> beans) {
        list = beans;
        notifyDataSetChanged();
    }
}
